import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Word {

	private XWPFDocument doc;
	
	private XWPFParagraph currentXWPFParagraph;

	public Word createDoc() {
		this.doc = new XWPFDocument();
		return this;
	}
	
	public XWPFParagraph createParagraph() {
		this.currentXWPFParagraph = this.doc.createParagraph();
		this.currentXWPFParagraph.setAlignment(ParagraphAlignment.LEFT);
		return this.currentXWPFParagraph;
	}
	
	public XWPFRun createRun() {
		XWPFRun run = this.currentXWPFParagraph.createRun();
		run.setFontSize(9); // 小五
		return run;
	}
	
	public void write(File f) {
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(f);
			this.doc.write(fos);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			IOUtils.closeQuietly(fos);
		}
	}

	public XWPFDocument getDoc() {
		return doc;
	}

	public XWPFParagraph getCurrentXWPFParagraph() {
		return currentXWPFParagraph;
	}
	
}
